package com.example.rocketmq.service.impl;

import com.example.rocketmq.dao.ProductRepository;
import com.example.rocketmq.entity.Product;
import com.example.rocketmq.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Optional;


/**
 * @author kangshuai
 */
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductRepository productRepository;

    @Override
    public Product findOne(Integer productId) {
        Optional<Product> productOptional = productRepository.findById(productId);
        return productOptional.get();
    }

    @Override
    public void save(Product product) {
        Date date = new Date();
        product.setCreateTime(date);
        product.setUpdateTime(date);
        productRepository.save(product);
    }
}
